<style lang="less" scoped>
  /deep/.el-dialog--center .el-dialog__body {
    padding: 28px 20px 43px!important;
  }
  /deep/.el-form-item__label {
    padding-right: 0;
  }
</style>
<template>
  <el-dialog v-el-drag-dialog
    id="sendImg"
    title="影像发送"
    :append-to-body='true'
    :visible.sync="sendImgShow"
    :before-close="SendImgClose"
    width="500px"
    top="3%"
    center>
    <div class="of">
      <el-form class="of" label-position="right">
        <div class="of fl pb25" style="width: 460px;">
          <div class="f14 mb14" v-if="sendImgData.length === 1">准备发送...</div>
          <div class="f14 mb14" v-if="sendImgData.length > 1">准备发送影像检查数：{{ sendImgData.length }}</div>
          <div class="f14 bg_f5 h133 pl20 pt20 mb28 boxs bradius5" v-if="sendImgData.length === 1">
            <div>
              <span class="mr30">{{ sendImgData[0]['other_patient_name'] }}</span>
              <span class="mr30">{{ sendImgData[0]['modalities_in_study'] }}</span>
              <span>{{ sendImgData[0]['study_date_time'] }}</span>
            </div>
            <div class="mt15">检查编号：{{ sendImgData[0]['accession_number'] }}</div>
            <div class="mt15">检查描述：{{ sendImgData[0]['study_description'] }}</div>
          </div>
          <div class="w100 clear_fixed">
            <el-form-item label="目标节点：" label-width="70px">
              <el-select v-model="routingnode" size="medium" style="width: 100%">
                <el-option
                  v-for="item in routingNodes"
                  :key="item.id"
                  :label="item.node_name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer fr">
        <el-button @click="SendImgClose" size="medium" class="mr20">取 消</el-button>
        <el-button type="primary" @click="SendImgSave" size="medium">确 定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import CommonTable from '@/components/common/CommonTable'

export default {
  data () {
    return {
      routingnode: '',
      routingNodes: [],
      timeId: null
    }
  },
  props: ['sendImgShow', 'sendImgData'],
  components: {
    CommonTable
  },
  watch: {
    sendImgData(newVal) {
      console.log(newVal)
    }
  },
  methods: {
    SendImgClose () {
      this.$emit('SendImgClose', '')
    },
    SendImgSave () {
      this.sendImg()
    },
    async sendImg() {
      if(!this.routingnode) {
        this.$message({
          type: 'warning',
          message: '请选择目标节点'
        })
        return
      }
      let idArr = this.sendImgData.map(ele => ele['id'])
      let res = await this.$pacsApi.pacsApi.sendImg(idArr, this.routingnode)
      let { code, msg } = res
      if(code === 0) {
        this.$message({
          type: 'success',
          message: msg
        })
        this.$store.commit('imgSend/SET_ALERT_SHOW', true)
        this.$store.dispatch('imgSend/pollingGetSendProgressRate') // 开始轮询
        this.SendImgClose()
      }
    },

    async getRoutingNodes() {
      let res = await this.$pacsApi.pacsApi.getRoutingNodes()
      let { code, data } = res
      if(code === 0) {
        this.routingNodes = data
      }
    }
  },
  mounted () {
    this.getRoutingNodes()
  }
}
</script>
